<?php
# Copyright (c) 2012 Jeckyhl (jeckyhl@SourceForge)

class UserCcPlugin extends MantisPlugin {
	function register() {
		$this->name = 'User CC';
		$this->description = plugin_lang_get("description");
		$this->page = 'config';

		$this->version = '1.0.0';
		$this->requires = array(
			'MantisCore' => '1.2.11',
		);

		$this->author	= 'Jeckyhl';
		$this->contact	= 'jeckyhl at SourceForge.net';
		$this->url		= 'http://code.google.com/p/mantisbt-usercc-plugin';
	}
	
	function hooks() {
		return array(
			"EVENT_NOTIFY_USER_INCLUDE" => "notify_user_include"
		);
	}

	/**
	* EVENT_NOTIFY_USER_INCLUDE :
	* This event allows a plugin to specify a set of users 
	* to be included as recipients for a notification
	* The set of users returned is added to the list of recipients already 
	* generated from the existing notification flags and selection process. 
	* 
	* Parameters
	* - <Integer>: Bug ID
	* - <String>: Notification type
	*
	* Return Value
	* - <Array>: User IDs to include as recipients
	*/
	public function notify_user_include( $event, $bug_id, $type ) {
		$userName = plugin_config_get('user_cc_name');
		if (empty($userName)) {
			# No userCC configured --> return empty array
			return array();
		}
		$userId = user_get_id_by_name($userName);
		if (!$userId) {
			# user_cc_name doesn't match any existing user --> return empty array
			return array();
		}
		# return User IDs to include as recipient
		return array($userId);
	}
	
	function config() {
        return array(
            'user_cc_name' => ''
        );
    }
}

?>